package com.twt.survey2025spring.exception;

import com.mysql.cj.jdbc.exceptions.MysqlDataTruncation;
import com.twt.survey2025spring.utils.response.CodeEnum;
import com.twt.survey2025spring.utils.response.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice("com.twt.survey.controller")
public class GlobalExceptionHandler {

    @ExceptionHandler(IllegalStateException.class)
    public ResultBody checkNull(IllegalStateException e){
        log.error("IllegalStateException: " + e.getMessage(), e);
        return new ResultBody(CodeEnum.UNFINISHED_STATUS);
    }

    @ExceptionHandler(NullPointerException.class)
    public ResultBody checkNullPointer(NullPointerException e){
        log.error("NullPointerException: " + e.getMessage(), e);
        return new ResultBody(CodeEnum.UNFINISHED_STATUS);
    }

    @ExceptionHandler(MysqlDataTruncation.class)
    public ResultBody checkDataLength(MysqlDataTruncation e){
        log.error("MysqlDataTruncation: " + e.getMessage(), e);
        return new ResultBody(CodeEnum.DATA_TOO_LONG);
    }

}
